package com.beiding.t;

import com.google.common.math.BigIntegerMath;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.MathContext;
import java.math.RoundingMode;
import java.util.List;

/**
 * @author 丁常磊
 * @date 2022/6/23 16:38
 */

public class 排列组合测试 {

    public static void main(String[] args) {

        int ct = 20;
        double sec = 0.5;

        double[] po = new double[ct+1];

        for (int i = 0; i <= ct; i++) {
            po[i] = test(sec, ct, i);
        }

        //绘制图形

        draw(po);

    }

    public static void draw(double[] ds) {

        int cn = 100;

        for (int j = 0; j < ds.length; j++) {
            double d = ds[j];
            int c = (int) (cn * d);
            System.out.print(j + "\t");
            for (int i = 0; i < c; i++) {
                System.out.print("-");
            }
            System.out.println();
        }


    }

    public static double test(double z, long m, long n) {
        long c = c(m, n);
        return c * Math.pow(z, n) * Math.pow((1 - z), (m - n));
    }

    public static long c(long m, long n) {
        BigDecimal f = new BigDecimal(1);
        MathContext mathContext = new MathContext(10, RoundingMode.CEILING);
        for (long i = 0; i < n; i++) {
            f = f.multiply(new BigDecimal(m - i)).divide(new BigDecimal(n - i), mathContext);
        }
        return f.longValue();
    }


}
